package com.woniuxy.oa.web;

import com.woniuxy.oa.entity.ResponseVO;
import com.woniuxy.oa.entity.Role;
import com.woniuxy.oa.service.PermissionService;
import com.woniuxy.oa.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("role")
@CrossOrigin("*")
public class RoleController {
    @Autowired
    private RoleService roleService;
    private PermissionService permissionService;

    /**
     * 查询角色
     *
     * @param role
     * @return
     */
    @RequestMapping("/list")
    public ResponseVO list(@RequestBody(required = false) Role role) {
        return new ResponseVO<>("200", "查询成功", roleService.getPageBean(role, role.getPage()));
    }

    /**
     * 增加角色
     *
     * @param role
     * @return
     */
    @PostMapping("/add")
    public ResponseVO<String> add(@RequestBody Role role) {
        roleService.add(role);
        return new ResponseVO<>("200", "增加角色成功", null);
    }

    /**
     * 逻辑删除角色
     *
     * @param ids
     * @return
     */
    @GetMapping("del/{ids}")
    public ResponseVO del(@PathVariable String[] ids) {
        for (String id : ids) {
            System.out.println("id: " + id);
        }
        roleService.delById(ids);
        return new ResponseVO("200", "删除成功", null);
    }

    /**
     * 查询角色所拥有的权限
     *
     * @param id
     * @return
     */
    @GetMapping("/perm/{id}")
    public ResponseVO permList(@PathVariable String id) {
        return new ResponseVO<>("200", "查询成功", roleService.getPerm(id));
    }
}